package com.vehicle.controller;


import com.vehicle.service.CategoryService;
import com.vehicle.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 校园车辆管理系统
 * @since 2023-04-21
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    //根据车类型名字添加车的类型
    @PostMapping("/add/{categoryName}")
    public ResultVO addCategory(HttpServletRequest request, @PathVariable("categoryName") String categoryName){
        String ip = request.getRemoteAddr();
        String id = request.getHeader("id");
        return ResultVO.succ(categoryService.addCategoryByName(ip,Integer.parseInt(id),categoryName));
    }


    //删除可停车类型
    @DeleteMapping("/deleteById/{categoryId}")
    public ResultVO deleteCategoryById(HttpServletRequest request,@PathVariable("categoryId") Integer categoryId) {
        String ip = request.getRemoteAddr();
        String id = request.getHeader("id");
        return ResultVO.succ(categoryService.deleteCategoryById(ip,Integer.parseInt(id),categoryId));
    }

    //获取所有的车辆类型
    @GetMapping("/categoryName")
    public ResultVO getAllCategoryName(){
        return ResultVO.succ(categoryService.getAllCategoryName());
    }

    //获取所有的车辆类型
    @GetMapping("/AllCategory/{page}/{size}")
    public ResultVO getAllCategory(@PathVariable("page") String page,@PathVariable("size") String size){
        return ResultVO.succ(categoryService.getAllCategory(Integer.parseInt(page),Integer.parseInt(size)));
    }

    @GetMapping("/CategoryNameById/{id}")
    public String getCategoryNameById(@PathVariable("id") Integer id){
       return categoryService.getNameById(id);
    }



}

